<template>
  <div class="container">
    <div class="btnGroup">
      <el-button type="primary" @click="toResume">完善简历</el-button>
      <el-button @click="toSubmitJob" type="primary">我要发布</el-button>
      <el-button type="primary" @click="toMySubmit">我发布的</el-button>
    </div>
    <el-card style="margin: 10px 0;">
      <div>热门企业</div>
      <company-list></company-list>
    </el-card>
    <el-card>
      <div style="margin-bottom: 10px;">招聘信息</div>
      <el-select v-model="chooseModule" @change="moduleChange">
        <el-option :value="1" label="实习"></el-option>
        <el-option :value="2" label="校招"></el-option>
        <el-option :value="3" label="社招"></el-option>
      </el-select>
      <div class="itemBox">
        <div v-for="item in jobList" :key="item.id" class="jobItem" @click="toJobDetail(item.id)">
          <div class="itemHeader">
            <span class="post">{{item.post}}</span>
            <span class="salary">{{item.fromMoney+'~'+item.toMoney+'K'}} * {{12+item.months}}薪</span>
          </div>
          <div class="require">
            <span class="workPlace">{{item.workPlace}}</span>
            <span>{{educationMap[item.education]}}</span>
          </div>
          <div class="company">
            <div class="companyInfo">
              <img :src="item.companyAvatarUrl" alt="">
              <span>{{item.companyName}}</span>
            </div>
            <span>{{item.industry}}</span>
        </div>
        </div>
      </div>
    </el-card>
  </div>
</template>

<script>
import CompanyList from '../components/CompanyList.vue'
export default {
  components: { CompanyList },
  data () {
    return {
      chooseModule: '',
      educationMap: {
        1: '博士后',
        2: '博士',
        3: '硕士',
        4: '本科',
        5: '专科',
        6: '高中',
        7: '初中',
        8: '小学'
      },
      jobList: []
    }
  },
  methods: {
    toMySubmit () {
      this.$router.push('/mySubmitJob')
    },
    moduleChange (value) {
      this.getJobsList(value)
    },
    toJobDetail (id) {
      this.$router.push(`/job/detail/${id}`)
    },
    toResume () {
      this.$router.push('/resume')
    },
    toSubmitJob () {
      this.$router.push('/submitJob')
    },
    async getJobsList (module) {
      if (module) {
        const {data: res} = await this.$http.get(`/job/list/${module}`)
        this.jobList = res
      } else {
        const {data: res} = await this.$http.get(`/job/list`)
        this.jobList = res
      }
    }
  },
  created () {
    this.$store.commit('setChoose', 'job')
    this.getJobsList()
  }
}
</script>

<style scoped lang="less">
.container {
  min-width: 1400px;
  padding: 10px 100px 0 100px;
  .btnGroup {
    margin-bottom: 10px;
  }
  .itemBox {
    display: flex;
    flex-wrap: wrap;
    .jobItem {
      box-sizing: border-box;
      width: 23%;
      background-color: #f8f8f9;
      margin-right: 15px;
      padding: 15px;
      border-radius: 5px;
      margin-top: 15px;
    }
    .jobItem:hover {
      background-color: #fff;
      box-shadow:#eeeef1 0px 0px 3px 3px;
      transform: translate(0,-5px);
      transition: transform 0.5s;
      cursor: pointer;
      .require {
        border-bottom: 1px solid #eee;
      }
    }
  }
  .itemHeader {
    display: flex;
    justify-content: space-between;
    .post {
      margin-bottom: 5px;
    }
    .salary {
      color: #3f8aee;
    }
  }
  .require {
    display: flex;
    padding-bottom: 10px;
    margin-bottom: 10px;
    .workPlace {
      padding-right: 10px;
      border-right: 1px solid #eee;
      margin-right: 10px;
    }
  }
  .company {
    display: flex;
    justify-content: space-between;
    align-items: center;
    .companyInfo {
      display: flex;
      align-items: center;
      img {
        width: 30px;
        height: 30px;
        border-radius: 50%;
        margin-right: 5px;
    }
    }
  }
}

</style>
